package com.dawn.module.hospital.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * xml文件处理
 */
public class XmlTools {

    /**
     * 处理检验报告数据
     * @param dataMap
     * @return
     */
    public static Map<String, Object> dealJY_Xml(Map dataMap){
        Map<String, Object> resMap = new HashMap<>();
        try {
            //报告名称
            String title = String.valueOf(dataMap.get("TITLE"));
            if(title!=null){
                resMap.put("title",title);
            }

            //姓名、科室等信息
            List<Map> patiList = (List<Map>) dataMap.get("PATI");
            if(patiList != null){
                for (Map p : patiList) {
                    List<Map> rowList = (List<Map>) p.get("ROW");
                    for(Map row : rowList){
                        resMap.putAll(row);
                    }
                }
            }

            //检验结果
            List<Map> tableList = (List<Map>) dataMap.get("TABLE");
            if(tableList != null){
                for (Map map : tableList) {
                    List<Map> rowList = (List<Map>) map.get("ROW");
                    for(int i=0; i<1; i++){//第一行 表头
                        Map p = rowList.get(0);
                        resMap.put("head",p);
                    }
                    rowList.remove(0);
                    resMap.put("items",rowList);
                }
            }

            //采样时间及备注
            List<Map> infoList = (List<Map>) dataMap.get("INFO");
            if(infoList != null){
                for (Map p : infoList) {
                    if(p.get("JYXX")!=null){
                        List<Map> jxxxList = (List<Map>) p.get("JYXX");
                        for (Map map : jxxxList) {
                            resMap.putAll(map);
                        }
                    }
                    resMap.putAll(p);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resMap;
    }

    /**
     * 处理检查报告数据
     * @param dataMap
     * @return
     */
    public static Map<String, Object> dealJC_Xml(Map dataMap){
        Map<String, Object> resMap = new HashMap<>();
        List<Map> mapList = (List<Map>) dataMap.get("body");
        if(mapList!=null && mapList.size()>0){
            dataMap = mapList.get(0);
            resMap.putAll(dataMap);
        }else {
            return resMap;
        }
        return resMap;
    }



    public static void main(String[] args){

    }

}
